﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WDA.Core;

namespace Sample
{
   public class SimpleLoadBalancer : ILoadBalancer
   {
      #region ILoadBalancer Members
      public Guid ChooseBestServiceHost(IEnumerable<KeyValuePair<Guid, object>> serviceMonitors)
      {
         TimeSpan bestTime = TimeSpan.MaxValue;
         Guid bestHost = Guid.Empty;
         foreach (KeyValuePair<Guid, object> monitor in serviceMonitors)
         {
            IMonitorService svc = (IMonitorService)monitor.Value;
            TimeSpan time = svc.GetAverageExecutionTime();
            if (time < bestTime)
            {
               bestTime = time;
               bestHost = monitor.Key;
            }
         }
         return bestHost;        
      }
      #endregion
   }
}
